package org.example.market.controller;

import org.example.market.entity.Role;
import org.example.market.service.RoleService;
import org.example.market.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping
    public Result<List<Role>> getAllRoles() {
        return roleService.getAllRoles();
    }

    @PostMapping
    public Result<Role> addRole(@RequestBody Role role) {
        return roleService.addRole(role);
    }

    @GetMapping("/{id}")
    public Result<Role> getRoleById(@PathVariable Long id) {
        return roleService.getRoleById(id);
    }

    @PutMapping
    public Result<Role> updateRole(@RequestBody Role role) {
        return roleService.updateRole(role);
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteRole(@PathVariable Long id) {
        return roleService.deleteRole(id);
    }
}